package cq.com.cn.dao;

import cq.com.cn.model.UserModel;
import cq.com.cn.utils.JDBCUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

public class UserDao {
    private static final String FINDUSERBYEMAI="select * from user where email=?";
    private static final String INSERTtUSER="INSERT INTO USER(email,loginName,niceName,pwd,gender,phone,remark,lastLoginTime,account) values(?,?,?,?,?,?,?,now(),1000)";
    private static final String USERLOGIN="select * from user where loginName=? and pwd=?";

    public UserModel userLogin(String loginName,String pwd){
         return JDBCUtils.findOne(UserModel.class,USERLOGIN,new Object[]{loginName,pwd});
    }

    public UserModel findUserByEmail(String email){
        return JDBCUtils.findOne(UserModel.class,FINDUSERBYEMAI,email);
    }


    public void insertUser(UserModel user) {
        if(StringUtils.isNoneBlank(user.getRemark())){
            user.setRemark(user.getRemark().trim());
        }
        Object  [] objArray=new Object[]{user.getEmail(),user.getLoginName(),user.getNiceName(),user.getPwd(),user.getGender(),user.getPhone(),user.getRemark()};
        JDBCUtils.operater(INSERTtUSER,objArray);
    }

}
